package com.explorx.sns.puma.im.core.chat.command;

import com.alibaba.fastjson2.JSON;
import com.explorx.sns.puma.im.core.chat.message.ChatMessage;
import com.explorx.sns.puma.im.core.chat.message.MessageCmd;
import com.explorx.sns.puma.im.core.controller.MessageGatewayService;
import lombok.Data;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class DeleteMessageCommand implements MessageCommand{

    @Resource
    private MessageGatewayService messageGatewayService;

    @Override
    public void execute(ChatMessage cmdData) {
        DeleteMessageData deleteMessageData= (DeleteMessageData) parseCmd(cmdData.getMessage());
        messageGatewayService.deleteMessage(cmdData.getSenderId(),cmdData.getCid(),deleteMessageData.getMsgId());
    }

    @Override
    public Object parseCmd(String cmdData) {
        return JSON.parseObject(cmdData, DeleteMessageData.class);
    }

    @Override
    public int cmd() {
        return MessageCmd.DELETE_MSG.getValue();
    }

    @Data
    static  class DeleteMessageData{
        private Long msgId;
    }
}
